from __future__ import annotations

from dataclasses import dataclass
from math import log, pi


@dataclass
class DewateringDesign:
    discharge_m3_h: float
    well_count: int
    spacing_m: float
    depth_m: float
    note: str


def design_wellpoint(radius_of_influence_m: float, permeability_m_s: float, drawdown_m: float, pit_perimeter_m: float) -> DewateringDesign:
    """井点降水（承压/潜水简化）：Q ≈ 2πkH ln(R/r_w)，并估算井数与间距。"""

    k = permeability_m_s
    H = drawdown_m
    R = radius_of_influence_m
    rw = 0.1
    Q_s = 2 * pi * k * H * max(0.1, log(R / rw))  # m3/s
    Q_h = Q_s * 3600.0
    spacing = 2.0 * rw * 10.0
    n = max(2, int(pit_perimeter_m / max(0.1, spacing)))
    return DewateringDesign(discharge_m3_h=Q_h, well_count=n, spacing_m=spacing, depth_m=H + 2.0, note="经验估算，需水文参数复核")


@dataclass
class UpliftCheck:
    safety_factor: float
    note: str


def check_base_uplift(gamma_sat_kN_m3: float, water_table_depth_m: float, excavation_depth_m: float, submerged_unit_weight_kN_m3: float = 10.0) -> UpliftCheck:
    """抗底隆起：取有效重度与水头差计算抗隆起安全系数。"""

    H_w = max(0.0, excavation_depth_m - water_table_depth_m)
    uplift = 9.81 * H_w / 9.81
    resistance = submerged_unit_weight_kN_m3 * excavation_depth_m
    Fs = resistance / max(1e-6, uplift)
    return UpliftCheck(safety_factor=Fs, note="Fs≥1.25 为宜")


